


/* IV Event - study graphs */


use "G:\Data\Workdata\707677\FKYY7677\Debt_relief\Statafiles\Revision\Data\panel_iv_long", replace

cd "G:\Data\Workdata\707677\FKYY7677\Debt_relief\Statafiles\Outputs\Revision\FINAL"

keep if time==1

egen lawyer_id_unique =group(lawyerid court) // Unique lawyer id within courts. some lawyers work in multiple courts
bys lawyer_id_unique: egen n_lawyer=count(lawyer_id_unique)
egen mean_lawyer_leniency= mean(granted), by(lawyer_id_unique)

gen iv_judge2_all = (mean_lawyer_leniency*n_lawyer - granted)/(n_lawyer-1)

gen iv_lawyer2=iv_judge2_all-(iv_court-granted)/(obs_court-1)


keep if n_lawyer>=20

egen n_judge=nvals(lawyer_id_unique), by(court aar)



tab n_judge

keep if n_judge>1

keep pnr iv_lawyer2 lawyer_id_unique


merge 1:m pnr using "G:\Data\Workdata\707677\FKYY7677\Debt_relief\Statafiles\Revision\Data\panel_iv_long"
keep if _merge==3
drop _merge
keep if pyear>=1988

tab lawyer_id_unique, gen(lawyer_dum)


encode(edu_type_m1), gen(primary_school)


/* Code oprindelsesland */
gen race=.
replace race=1 if ie_type_m1==1 // Danish
replace race=2 if ie_type_m1==2 // Foreign
replace race=3 if ie_type_m1==. // missing

tab race, gen(racedum)

// Persons in the house 

gen house_number=.

replace house_number=1 if antpersf_d_m1==1
replace house_number=2 if antpersf_d_m1==2
replace house_number=3 if antpersf_d_m1==3
replace house_number=4 if antpersf_d_m1>3 & antpersf_d_m1!=.
replace house_number=5 if antpersf_d_m1==.


tab house_number, gen(housedum)


gen housing_missing=1 if house_number==5
replace housing_missing=0 if house_number!=5

// age 
gen age_0_40=(age0>=1 & age0<=40 & age0!=.)
gen age_41_50=(age0>=41 & age0<=50 & age0!=.)
gen age_51_60=(age0>=51 & age0<=60 & age0!=.)
gen age_61_70=(age0>=61 & age0<=70 & age0!=.)

// Attrition

gen attrition=0
replace attrition=1 if formue_real==.


// Selfemployed

gen selfemployed=1 if netovskud_real!=0 & netovskud_real!=.
replace selfemployed=0 if netovskud_real==0 & netovskud_real!=.

// Education edu_type_m1
encode(edu_type_m1), gen(edu_prior)
gen lower_secondary=(edu_prior<=2 & edu_prior!=.)
gen higher_secondary=(edu_prior==3 & edu_prior!=.)
gen university=(edu_prior>3 & edu_prior!=.)
gen edu_missing=(edu_prior==.)

// Children in the home

gen children_inhouse=1 if antboernf_m1>0 & antboernf_m1!=.
replace children_inhouse=0 if antboernf_m1==0 
replace children_inhouse=0 if antboernf_m1==. 

gen children_missing=0
replace children_missing=1 if antboernf_m1==.

// Wage 

egen timelon_groups=xtile(timelon_real_m1), nq(4) by(pyear)

replace timelon_groups=5 if timelon_groups==.  // category for missing

tab timelon_groups, gen(timelon_dum)






local sumvar "erhvervsindk employed_pstill unemployed_pstill  social  legmarried house passiv aktiv formue"


foreach var in `sumvar'  {

egen `var'_mean=rowmean(`var'_m2 `var'_m3 `var'_m4 `var'_m1)

}



local sumvar "erhvervsindk employed_pstill unemployed_pstill  social  legmarried house passiv aktiv formue"


foreach var in `sumvar'  {

egen `var'_mean_1=rowmean(`var'_m2 `var'_m3 `var'_m4 `var'_m5)

}

local sumvar "erhvervsindk employed_pstill unemployed_pstill  social  legmarried house passiv aktiv formue"

foreach var in `sumvar'  {

egen `var'_mean_2=rowmean(`var'_m6 `var'_m3 `var'_m4 `var'_m5)

}

local sumvar "erhvervsindk employed_pstill unemployed_pstill  social  legmarried house passiv aktiv formue"


foreach var in `sumvar'  {

egen `var'_mean_3=rowmean(`var'_m6 `var'_m7 `var'_m4 `var'_m5)

}


local sumvar "erhvervsindk employed_pstill unemployed_pstill  social  legmarried house passiv aktiv formue"


foreach var in `sumvar'  {

egen `var'_mean_4=rowmean(`var'_m6 `var'_m7 `var'_m8 `var'_m5)

}

egen court_pyear =group(court pyear) 
tab court_pyear

tab time

tab aar, gen(aardum)



egen timelon_groups_m2=xtile(timelon_real_m2), nq(4) by(pyear)

replace timelon_groups_m2=5 if timelon_groups_m2==.  // category for missing

tab timelon_groups_m2, gen(timelon_dumm2)


egen timelon_groups_m3=xtile(timelon_real_m3), nq(4) by(pyear)

replace timelon_groups_m3=5 if timelon_groups_m3==.  // category for missing

tab timelon_groups_m3, gen(timelon_dumm3)


egen timelon_groups_m4=xtile(timelon_real_m4), nq(4) by(pyear)

replace timelon_groups_m4=5 if timelon_groups_m4==.  // category for missing

tab timelon_groups_m4, gen(timelon_dumm4)


egen timelon_groups_m5=xtile(timelon_real_m5), nq(4) by(pyear)

replace timelon_groups_m5=5 if timelon_groups_m5==.  // category for missing

tab timelon_groups_m5, gen(timelon_dumm5)


local depvar "erhvervsindk_real"


foreach var in `depvar' {

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_4 employed_pstill_mean_4 unemployed_pstill_mean_4 social_mean_4 racedum1  legmarried_m5 house_m5 passiv_m5 aktiv_m5 higher_secondary university timelon_dumm51 timelon_dumm52 timelon_dumm53 timelon_dumm54"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-4 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus4


// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_3 employed_pstill_mean_3 unemployed_pstill_mean_3 social_mean_3 racedum1  legmarried_m4 house_m4 passiv_m4 aktiv_m4 higher_secondary university timelon_dumm41 timelon_dumm42 timelon_dumm43 timelon_dumm44"



ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-3 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus3

// reg

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_2 employed_pstill_mean_2 unemployed_pstill_mean_2 social_mean_2 racedum1 legmarried_m3 house_m3 passiv_m3 aktiv_m3 higher_secondary university timelon_dumm31 timelon_dumm32 timelon_dumm33 timelon_dumm34"



ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==-2 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus2

// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_1 employed_pstill_mean_1 unemployed_pstill_mean_1 social_mean_1 legmarried_m2 racedum1 house_m2 passiv_m2 aktiv_m2 higher_secondary university timelon_dumm21 timelon_dumm22 timelon_dumm23 timelon_dumm24"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'   if time==-1, absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus1




local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean employed_pstill_mean unemployed_pstill_mean legmarried_m1 racedum1 housedum1 passiv_m1 aktiv_m1 higher_secondary university social_mean edu_missing housing_missing timelon_dum1 timelon_dum2 timelon_dum3 timelon_dum4 house_m1"







ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==0 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_null


forvalues i=1(1)16 {

ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==`i' , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_`i'
	
}


#delimit ; 


coefplot i_minus4 || i_minus3|| i_minus2 || i_minus1 || i_null ||  i_1 || i_2 || i_3 || i_4 || i_5 || i_6 || i_7 || i_8 || i_9 || i_10 || i_11 || i_12 || i_13 || i_14 || i_15 || i_16,   keep(granted) vertical  ///
bycoefs ///
 ///




mcolor(black)

ciopts(lcolor(black) recast(rcap))

title("")


xlabel(1 "-4" 2 " " 3 "-2" 4 " " 5 "0" 6 " " 7 "2" 8 " " 9 "4" 10 " " 11 "6" 12 " " 13 "8" 

14 " " 15 "10" 16 " " 17 "12" 18 " " 19 "14" 20 " " 21 "16", angle(0) nogrid labsize(medsmall))

ylabel(-100000 "-100" -50000 "-50" 0 "0" 50000 "50" 100000 "100" 150000 "150",nogrid angle(0) labsize(medsmall))


yscale(titlegap(*-3))


yline(0, lcolor(black))

xline(4, lcolor(black) lpattern(dash))

ytitle("Earned Income", size(medium))

xtitle("Years", size(medsmall))

title("")


graphregion(fcolor(white)) bgcolor(white) scheme(s1color)

name(`var', replace)


;


#delimit cr






}
*/
* AKTIVER
*/

local depvar " aktiv_real "

foreach var in `depvar' {


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_4 employed_pstill_mean_4 unemployed_pstill_mean_4 social_mean_4 racedum1  legmarried_m5 house_m5 passiv_m5 aktiv_m5 higher_secondary university timelon_dumm51 timelon_dumm52 timelon_dumm53 timelon_dumm54"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-4 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus4


// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_3 employed_pstill_mean_3 unemployed_pstill_mean_3 social_mean_3 racedum1  legmarried_m4 house_m4 passiv_m4 aktiv_m4 higher_secondary university timelon_dumm41 timelon_dumm42 timelon_dumm43 timelon_dumm44"



ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-3 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus3

// reg

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_2 employed_pstill_mean_2 unemployed_pstill_mean_2 social_mean_2 racedum1 legmarried_m3 house_m3 passiv_m3 aktiv_m3 higher_secondary university timelon_dumm31 timelon_dumm32 timelon_dumm33 timelon_dumm34"



ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==-2 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus2

// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_1 employed_pstill_mean_1 unemployed_pstill_mean_1 social_mean_1 legmarried_m2 racedum1 house_m2 passiv_m2 aktiv_m2 higher_secondary university timelon_dumm21 timelon_dumm22 timelon_dumm23 timelon_dumm24"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'   if time==-1, absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus1




local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean employed_pstill_mean unemployed_pstill_mean legmarried_m1 racedum1 housedum1 passiv_m1 aktiv_m1 higher_secondary university social_mean edu_missing housing_missing timelon_dum1 timelon_dum2 timelon_dum3 timelon_dum4 house_m1"






ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==0 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_null


forvalues i=1(1)16 {

ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==`i' , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_`i'
	
}


#delimit ; 


coefplot i_minus4 || i_minus3|| i_minus2 || i_minus1 || i_null ||  i_1 || i_2 || i_3 || i_4 || i_5 || i_6 || i_7 || i_8 || i_9 || i_10 || i_11 || i_12 || i_13 || i_14 || i_15 || i_16,   keep(granted) vertical  ///
bycoefs ///
 ///




mcolor(black)

ciopts(lcolor(black) recast(rcap))

title("")


xlabel(1 "-4" 2 " " 3 "-2" 4 " " 5 "0" 6 " " 7 "2" 8 " " 9 "4" 10 " " 11 "6" 12 " " 13 "8" 

14 " " 15 "10" 16 " " 17 "12" 18 " " 19 "14" 20 " " 21 "16", angle(0) nogrid labsize(medsmall))

ylabel(-500000 "-500"  0 "0"  500000 "500" 1000000 "1000",nogrid angle(0) labsize(medsmall))


yscale(titlegap(*-3))


yline(0, lcolor(black))

xline(4, lcolor(black) lpattern(dash))

ytitle("Assets", size(medium))

xtitle("Years", size(medsmall))

title("")


graphregion(fcolor(white)) bgcolor(white) scheme(s1color)

name(`var', replace)


;


#delimit cr






}

* EMPLOYMENT

local depvar "   employed_pstill  "


foreach var in `depvar' {

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_4 employed_pstill_mean_4 unemployed_pstill_mean_4 social_mean_4 racedum1  legmarried_m5 house_m5 passiv_m5 aktiv_m5 higher_secondary university timelon_dumm51 timelon_dumm52 timelon_dumm53 timelon_dumm54"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-4 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus4


// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_3 employed_pstill_mean_3 unemployed_pstill_mean_3 social_mean_3 racedum1  legmarried_m4 house_m4 passiv_m4 aktiv_m4 higher_secondary university timelon_dumm41 timelon_dumm42 timelon_dumm43 timelon_dumm44"



ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-3 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus3

// reg

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_2 employed_pstill_mean_2 unemployed_pstill_mean_2 social_mean_2 racedum1 legmarried_m3 house_m3 passiv_m3 aktiv_m3 higher_secondary university timelon_dumm31 timelon_dumm32 timelon_dumm33 timelon_dumm34"



ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==-2 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus2

// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_1 employed_pstill_mean_1 unemployed_pstill_mean_1 social_mean_1 legmarried_m2 racedum1 house_m2 passiv_m2 aktiv_m2 higher_secondary university timelon_dumm21 timelon_dumm22 timelon_dumm23 timelon_dumm24"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'   if time==-1, absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus1




local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean employed_pstill_mean unemployed_pstill_mean legmarried_m1 racedum1 housedum1 passiv_m1 aktiv_m1 higher_secondary university social_mean edu_missing housing_missing timelon_dum1 timelon_dum2 timelon_dum3 timelon_dum4 house_m1"




ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==0 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_null


forvalues i=1(1)16 {

ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==`i' , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_`i'
	
}


#delimit ; 


coefplot i_minus4 || i_minus3|| i_minus2 || i_minus1 || i_null ||  i_1 || i_2 || i_3 || i_4 || i_5 || i_6 || i_7 || i_8 || i_9 || i_10 || i_11 || i_12 || i_13 || i_14 || i_15 || i_16,   keep(granted) vertical  ///
bycoefs ///
 ///




mcolor(black)

ciopts(lcolor(black) recast(rcap))

title("")


xlabel(1 "-4" 2 " " 3 "-2" 4 " " 5 "0" 6 " " 7 "2" 8 " " 9 "4" 10 " " 11 "6" 12 " " 13 "8" 

14 " " 15 "10" 16 " " 17 "12" 18 " " 19 "14" 20 " " 21 "16", angle(0) nogrid labsize(medsmall))

ylabel(-0.2 "-20%"  0 "0 %"  0.2 "20 %" 0.4 "40 %",nogrid angle(0) labsize(medsmall))


yscale(titlegap(*-3))


yline(0, lcolor(black))

xline(4, lcolor(black) lpattern(dash))

ytitle("Employment", size(medium))

xtitle("Years", size(medsmall))

title("")


graphregion(fcolor(white)) bgcolor(white) scheme(s1color)

name(`var', replace)


;


#delimit cr






}

local depvar "    formue_real  "

foreach var in `depvar' {


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_4 employed_pstill_mean_4 unemployed_pstill_mean_4 social_mean_4 racedum1  legmarried_m5 house_m5 passiv_m5 aktiv_m5 higher_secondary university timelon_dumm51 timelon_dumm52 timelon_dumm53 timelon_dumm54"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-4 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus4


// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_3 employed_pstill_mean_3 unemployed_pstill_mean_3 social_mean_3 racedum1  legmarried_m4 house_m4 passiv_m4 aktiv_m4 higher_secondary university timelon_dumm41 timelon_dumm42 timelon_dumm43 timelon_dumm44"



ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-3 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus3

// reg

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_2 employed_pstill_mean_2 unemployed_pstill_mean_2 social_mean_2 racedum1 legmarried_m3 house_m3 passiv_m3 aktiv_m3 higher_secondary university timelon_dumm31 timelon_dumm32 timelon_dumm33 timelon_dumm34"



ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==-2 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus2

// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_1 employed_pstill_mean_1 unemployed_pstill_mean_1 social_mean_1 legmarried_m2 racedum1 house_m2 passiv_m2 aktiv_m2 higher_secondary university timelon_dumm21 timelon_dumm22 timelon_dumm23 timelon_dumm24"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'   if time==-1, absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus1




local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean employed_pstill_mean unemployed_pstill_mean legmarried_m1 racedum1 housedum1 passiv_m1 aktiv_m1 higher_secondary university social_mean edu_missing housing_missing timelon_dum1 timelon_dum2 timelon_dum3 timelon_dum4 house_m1"



ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==0 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_null


forvalues i=1(1)16 {

ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==`i' , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_`i'
	
}


#delimit ; 


coefplot i_minus4 || i_minus3|| i_minus2 || i_minus1 || i_null ||  i_1 || i_2 || i_3 || i_4 || i_5 || i_6 || i_7 || i_8 || i_9 || i_10 || i_11 || i_12 || i_13 || i_14 || i_15 || i_16,   keep(granted) vertical  ///
bycoefs ///
 ///




mcolor(black)

ciopts(lcolor(black) recast(rcap))

title("")


xlabel(1 "-4" 2 " " 3 "-2" 4 " " 5 "0" 6 " " 7 "2" 8 " " 9 "4" 10 " " 11 "6" 12 " " 13 "8" 

14 " " 15 "10" 16 " " 17 "12" 18 " " 19 "14" 20 " " 21 "16", angle(0) nogrid labsize(medsmall))

ylabel(-500000 "-500"  0 "0"  500000 "500" ,nogrid angle(0) labsize(medsmall))


yscale(titlegap(*-3))


yline(0, lcolor(black))

xline(4, lcolor(black) lpattern(dash))

ytitle("Wealth", size(medium))

xtitle("Years", size(medsmall))

title("")


graphregion(fcolor(white)) bgcolor(white) scheme(s1color)

name(`var', replace)


;


#delimit cr



}


local depvar "   bankgaeld_real  "

foreach var in `depvar' {


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_4 employed_pstill_mean_4 unemployed_pstill_mean_4 social_mean_4 racedum1  legmarried_m5 house_m5 passiv_m5 aktiv_m5 higher_secondary university timelon_dumm51 timelon_dumm52 timelon_dumm53 timelon_dumm54"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-4 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus4


// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_3 employed_pstill_mean_3 unemployed_pstill_mean_3 social_mean_3 racedum1  legmarried_m4 house_m4 passiv_m4 aktiv_m4 higher_secondary university timelon_dumm41 timelon_dumm42 timelon_dumm43 timelon_dumm44"



ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-3 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus3

// reg

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_2 employed_pstill_mean_2 unemployed_pstill_mean_2 social_mean_2 racedum1 legmarried_m3 house_m3 passiv_m3 aktiv_m3 higher_secondary university timelon_dumm31 timelon_dumm32 timelon_dumm33 timelon_dumm34"



ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==-2 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus2

// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_1 employed_pstill_mean_1 unemployed_pstill_mean_1 social_mean_1 legmarried_m2 racedum1 house_m2 passiv_m2 aktiv_m2 higher_secondary university timelon_dumm21 timelon_dumm22 timelon_dumm23 timelon_dumm24"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'   if time==-1, absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus1




local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean employed_pstill_mean unemployed_pstill_mean legmarried_m1 racedum1 housedum1 passiv_m1 aktiv_m1 higher_secondary university social_mean edu_missing housing_missing timelon_dum1 timelon_dum2 timelon_dum3 timelon_dum4 house_m1"





ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==0 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_null


forvalues i=1(1)16 {

ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==`i' , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_`i'
	
}


#delimit ; 


coefplot i_minus4 || i_minus3|| i_minus2 || i_minus1 || i_null ||  i_1 || i_2 || i_3 || i_4 || i_5 || i_6 || i_7 || i_8 || i_9 || i_10 || i_11 || i_12 || i_13 || i_14 || i_15 || i_16,   keep(granted) vertical  ///
bycoefs ///
 ///




mcolor(black)

ciopts(lcolor(black) recast(rcap))

title("")


xlabel(1 "-4" 2 " " 3 "-2" 4 " " 5 "0" 6 " " 7 "2" 8 " " 9 "4" 10 " " 11 "6" 12 " " 13 "8" 

14 " " 15 "10" 16 " " 17 "12" 18 " " 19 "14" 20 " " 21 "16", angle(0) nogrid labsize(medsmall))

ylabel(-400000 "-400" -200000 "-200"  0 "0"  200000 "200",nogrid angle(0) labsize(medsmall))


yscale(titlegap(*-3))


yline(0, lcolor(black))

xline(4, lcolor(black) lpattern(dash))

ytitle("Unsecured Debt", size(medium))

xtitle("Years", size(medsmall))

title("")


graphregion(fcolor(white)) bgcolor(white) scheme(s1color)

name(`var', replace)


;


#delimit cr




}

local depvar "   mortgage_real "


foreach var in `depvar' {


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_4 employed_pstill_mean_4 unemployed_pstill_mean_4 social_mean_4 racedum1  legmarried_m5 house_m5 passiv_m5 aktiv_m5 higher_secondary university timelon_dumm51 timelon_dumm52 timelon_dumm53 timelon_dumm54"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-4 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus4


// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_3 employed_pstill_mean_3 unemployed_pstill_mean_3 social_mean_3 racedum1  legmarried_m4 house_m4 passiv_m4 aktiv_m4 higher_secondary university timelon_dumm41 timelon_dumm42 timelon_dumm43 timelon_dumm44"



ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==-3 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus3

// reg

local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_2 employed_pstill_mean_2 unemployed_pstill_mean_2 social_mean_2 racedum1 legmarried_m3 house_m3 passiv_m3 aktiv_m3 higher_secondary university timelon_dumm31 timelon_dumm32 timelon_dumm33 timelon_dumm34"



ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==-2 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus2

// reg


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean_1 employed_pstill_mean_1 unemployed_pstill_mean_1 social_mean_1 legmarried_m2 racedum1 house_m2 passiv_m2 aktiv_m2 higher_secondary university timelon_dumm21 timelon_dumm22 timelon_dumm23 timelon_dumm24"


ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'   if time==-1, absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_minus1




local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean employed_pstill_mean unemployed_pstill_mean legmarried_m1 racedum1 housedum1 passiv_m1 aktiv_m1 higher_secondary university social_mean edu_missing housing_missing timelon_dum1 timelon_dum2 timelon_dum3 timelon_dum4 house_m1"




ivreghdfe `var' (granted=iv_lawyer2)  `Xvar_short'  if time==0 , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_null


forvalues i=1(1)16 {

ivreghdfe `var' (granted=iv_lawyer2) `Xvar_short'  if time==`i' , absorb(court_pyear) tol(1e-6) first cluster(lawyer_id_unique) 


eststo i_`i'
	
}


#delimit ; 


coefplot i_minus4 || i_minus3|| i_minus2 || i_minus1 || i_null ||  i_1 || i_2 || i_3 || i_4 || i_5 || i_6 || i_7 || i_8 || i_9 || i_10 || i_11 || i_12 || i_13 || i_14 || i_15 || i_16,   keep(granted) vertical  ///
bycoefs ///
 ///




mcolor(black)

ciopts(lcolor(black) recast(rcap))

title("")


xlabel(1 "-4" 2 " " 3 "-2" 4 " " 5 "0" 6 " " 7 "2" 8 " " 9 "4" 10 " " 11 "6" 12 " " 13 "8" 

14 " " 15 "10" 16 " " 17 "12" 18 " " 19 "14" 20 " " 21 "16", angle(0) nogrid labsize(medsmall))

ylabel(-200000 "-200"  0 "0"  200000 "200" 400000 "400" 600000 "600",nogrid angle(0) labsize(medsmall))


yscale(titlegap(*-3))


yline(0, lcolor(black))

xline(4, lcolor(black) lpattern(dash))

ytitle("Secured Debt", size(medium))

xtitle("Years", size(medsmall))

title("")


graphregion(fcolor(white)) bgcolor(white) scheme(s1color)

name(`var', replace)  


;


#delimit cr




}



* in one graph


graph combine erhvervsindk_real employed_pstill aktiv_real formue_real bankgaeld_real mortgage_real, graphregion(fcolor(white)) scheme(s1color) cols(2) rows(3) imargin(small)



graph export event_IV_panel_1988_full_control.pdf, replace
